package cn.lili.modules.payment.entity.dto;

import cn.lili.modules.order.order.entity.dos.OrderFlow;
import cn.lili.modules.payment.entity.enums.PaymentMethodEnum;
import cn.lili.modules.payment.entity.enums.PaymentSceneEnums;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * 分账请求参数
 */
@Data
public class ProfitSharingRequestDTO {

    @ApiModelProperty(value = "支付方式")
    private PaymentMethodEnum paymentMethodEnum;

    @ApiModelProperty(value = "订单号")
    private String orderSn;

    @ApiModelProperty(value = "店铺ID")
    private String storeId;

    @ApiModelProperty(value = "店铺名称")
    private String nickName;

    @ApiModelProperty(value = "分账总金额")
    private Double totalAmount;

    @ApiModelProperty(value = "店铺分账金额")
    private Double storeAmount;

    @ApiModelProperty(value = "支付场景")
    private PaymentSceneEnums paymentSceneEnums;

    @ApiModelProperty(value = "是否为特殊订单：特殊订单为某一端结算金额为负数，那么付款目标转向平台子商户，然后分账统一从平台余额中提取" +
            "如果是特殊订单，分账时需先校验入账出账是否相等，可能涉及多种支付方式")
    private Boolean specialOrder;

    @ApiModelProperty(value = "分账接收方列表")
    private List<OutOrderItem> outOrderItems;

    @ApiModelProperty(value = "绿色积分分佣")
    private List<OutPointOrderItem> outPointOrderItem;

    @ApiModelProperty(value = "F分分配")
    private List<OutFmoneyOrderItem> outFmoneyOrderItem;

    public ProfitSharingRequestDTO() {


    }

    public PaymentSceneEnums getPaymentSceneEnums() {
        if (paymentSceneEnums == null) {
            return PaymentSceneEnums.TRADE;
        }
        return this.paymentSceneEnums;
    }

    public ProfitSharingRequestDTO(OrderFlow orderFlow) {

        this.paymentMethodEnum = PaymentMethodEnum.valueOf(orderFlow.getPaymentMethod());

        this.orderSn = orderFlow.getOrderSn();

        this.storeId = orderFlow.getStoreId();

        this.nickName = orderFlow.getStoreName();

        this.totalAmount = orderFlow.getFlowPrice();

        this.storeAmount = orderFlow.getSellerSettlementPrice();

        this.outOrderItems = OutOrderItem.generateItems(orderFlow);

        this.outPointOrderItem = OutPointOrderItem.generateItems(orderFlow);

        this.outFmoneyOrderItem = OutFmoneyOrderItem.generateItems(orderFlow);

        this.specialOrder = orderFlow.getSpecialOrder();

    }
}
